package cn.dancepeak.controller;

import cn.dancepeak.domain.Login;
import cn.dancepeak.service.ILoginServiceImpl;
import cn.dancepeak.utils.R;
import cn.dancepeak.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginServiceImpl loginServiceImpl;

    @PostMapping("/account")
    public R account(@RequestBody Login login){
        try {
            String token = loginServiceImpl.account(login);
            return R.ok("登录成功！",token);
        } catch (BusinessException e) {
            return R.fail(e.getMessage());
        }catch (Exception e){
            return R.fail("系统错误！");
        }
    }


}
